home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / dev / e / rpmod1v1.lha / Modules / Tools / qsort.doc < prev    next >
Encoding:
Text File  |  1995-04-06  |  1.5 KB  |  58 lines

  1.     Generalized QuickSort for anything ( qsort.m )
  2.  
  3.     © Richard Perrott 4th April 1995 FreeWare
  4.       email: hcm94rp2@dmu.ac.uk
  5.  
  6. This module implements the quicksort algorithm in the most flexible way.
  7.  
  8.     PROC qsort(base,first,last,comp,swap)
  9.  
  10. base:
  11.     the start address of an ARRAY OF ? e.g. CHAR, INT, LONG, OBJECT ?.
  12.  
  13. first:
  14.     the lowest position you want to sorting from
  15.  
  16. last:
  17.     the highest position you want to sorting to
  18.  
  19. comp:
  20.     a pointer to a PROC to compare the value of two items 
  21.  
  22.     e.g.
  23.  
  24.     PROC comp(base:PTR TO LONG, position1, position2)
  25.       DEF item
  26.  
  27.       item := base[position]
  28.       IF item1 < find THEN RETURN -1
  29.       IF item1 > find THEN RETURN 1
  30.     ENDPROC 0
  31.  
  32. swap:
  33.     a pointer to a PROC ????(base, position_1, position_2)
  34.     to swap two items.
  35.  
  36. Note:
  37.   Any registers it uses are saved, but if your comp and swap
  38. routines use registers other than D0 and the caller of qsort
  39. needs them, then you will need to save them. qsort doesn't
  40. care which registers you use.
  41.  
  42.   The module contains 244 bytes of assembler / E code.
  43.  
  44.   The routine won't stay in a 68020+ code cache unless the
  45. PROCs it calls are tiny and very close to it.
  46.  
  47.   The routine has been heavily tested, though there are no promises
  48. and I won't be held responsible if you find bugs or you misuse the
  49. routine.
  50.  
  51.   If you do find any bugs then please email me.
  52.  
  53. References:
  54.     Programming and Problem Solving in Modula-2, Sanford Leestma
  55.     & Larry Nyhoff, © Macmillan 1992, USA, page 624-626
  56.  
  57.     ( beware the example in this book for Split() contains some bugs )
  58.